import sys
import struct

fp = open(sys.argv[1], 'rb')

assert fp.read(4) == 'XPRF'
assert fp.read(4) == '\x01\0\0\0'

offset = struct.unpack('i', fp.read(4))[0]

fp.read(12)

files = []

for x in xrange((offset - 24) / 8):
	_size, _offset = struct.unpack('II', fp.read(8))
	files.append({'size': _size, 'offset': _offset})

fp.seek(offset)
i = 0
buf = ''
while True:
	c = fp.read(1)
	if c == '\0':
		if not buf: break
		files[i]['name'] = buf
		buf = ''
		i += 1
	else:
		buf += c

for file in files:
	fp.seek(file['offset'])

	print 'extracting %(name)s (%(size)d bytes, offset 0x%(offset)x)' % file

	arc = open(file['name'], 'wb', 0)
	arc.write(fp.read(file['size']))
	arc.close()
